import pygame, math, sys    
from Block import Block

class Level():
    def __init__(self, level, screenSize):
        self.screenSize = screenSize
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.load(level)
       
       
    def load(self, level):
        geoMap="rsc/maps/"+ level +".lvl"
        thingMap="rsc/maps/"+ level +".tng"
        self.level = level
        self.blocks = []
        self.fblocks = []
        self.wblocks = []
        self.dblocks = []
        geofile = open(geoMap, "r")
        lines = geofile.readlines()
        geofile.close()
        newlines = []
        self.nspawn = False
       

        for line in lines:
            newline = ""
            for character in line:
                if character != "\n":
                    newline += character
            newlines += [newline]
           
        for y, line in enumerate(newlines):
            for x, c in enumerate(line):
                if c == "w":
                    self.blocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/city blocks/Wall1.png",(10,10))]
                if c == "g":
                    self.fblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/city blocks/window.png",(10,10))]
                if c == "c":
                    self.fblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/wood.png" ,(10,10))]
                if c == "s":
                    self.fblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/snow.png",(10,10))]
                if c == "r":
                    self.fblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/water2.png",(10,10))]
                if c == "o":
                    self.fblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/city blocks/MidRoadSide.png",(10,10))]
                if c == "f":
                    self.fblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/city blocks/MidRoadRB.png",(10,10))]
                if c == "d":
                    self.fblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/city blocks/MidRoad.png",(10,10))]
                if c == "l":
                    self.kblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/Lava.png",(10,10))]
                if c == "x":
                    self.blocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/city blocks/Dore1.png",(10,10))]
                if c == "h":
                    self.blocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/city blocks/rouf conection.png",(10,10))]
                if c == "i":
                    self.fblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/city blocks/rouf.png",(10,10))]
                if c == "p":
                    self.fblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/grass.png",(10,10))]
               
               
               
                   
        #----Done with file---
       
        thingfile = open(thingMap, "r")
        lines = thingfile.readlines()
        thingfile.close()
       
        newlines = []
       
        for line in lines:
            newline = ""
            for character in line:
                if character != "\n":
                    newline += character
            newlines += [newline]
           
        for y, line in enumerate(newlines):
            for x, c in enumerate(line):
                if c == "p":
                    self.dblocks += [Block([(x*10)+5, (y*10)+5], self.screenSize,"rsc/imgs/block/spawnspace.png",(10,10))]
#                if c == "N":
#                    self.mblocks += [self.levelLoader("N")]
                   

    def levelLoader(self, dir):
        if self.level == "map1":
            if self.dir == "N":
                return Block